<!DOCTYPE html>
<html>

<head>
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="zh-CN">
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <meta name="keywords" content="关键词" />
    <meta name="description" content="页面简介" />
    <link rel="icon" href="favicon.ico" />
    <link rel="shortcut icon" href="favicon.ico" />
    <link href="csaa/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="./csaa/fonts/iconfont/iconfont.css">
    <link rel="stylesheet" href="./csaa/fonts/materialicons/material-icons.css">

    <script src="./csaa/js/jquery.min.js"></script>
    <script src="./csaa/js/httpPath.js"></script>
    <script src="./csaa/js/httpUtils.js"></script>
    <script src="./csaa/js/site.js"></script>
    <title>全国青少年航空科学素质等级考试</title>
</head>

<body style="background-color: #efefef;">
    <!-- 头部 开始 -->
    <div class="header login_header">

    </div>
    <!-- 头部 结束 -->
    <div class="count_down">
        倒计时:
        <!-- <span class="time_show"></span> -->
        <!-- <span id="day_show"></span> -->
        <span id="hour_show"></span>
        <span id="minute_show"></span>
        <span id="second_show"></span>
    </div>


    <!-- 主体 开始 -->
    <div id="exam_main" class="main">
        <div class="exam_content">
            <div class="exam_top">
                <div class="title">--</div>
                <div class="exam_totaltime" style="text-align: center;">考试时长:<span class="text"></span>分钟</div>

                <div class="tips">提示：考试期间请勿关闭窗口、刷新页面！若想退出考试，请点击<span class="cancel btn btn_color_2 btn_out" title="将本次试卷作废。下次进入考试，将重新答题。">退出考试</span>按钮<a class="close"><i class="material-icons">&#xe14c;</i></a></div>
            </div>
            <div id="exam_box">
                <div class="list">

                </div>
            </div>
            <div class="manage_btnwrap">
                <span class="btn btn_out" title="将本次试卷作废。下次进入考试，将重新答题。">退出考试</span>
                <a id="btn_submit" class="btn btn_color_1 btn_submit">交卷</a>
            </div>
        </div>
    </div>
    <!-- 主体 结束 -->

    <div id="tmp_item_exam" style="display: none;">
        <div class="item">
            <div class="questiontype">--</div>
            <div class="question"></div>
            <div class="questionimg">
            </div>
            <div class="answer">

            </div>
        </div>
    </div>

    <div id="tmp_item_check" style="display:none">
        <label class="form_check">
			<input type="" name="answer_001" value="1" class="input_change">
			<span><span class="change_head"></span><span class="change_dun">、</span><span class="change_name"></span><span class="change_img"><img src="" ></span></span>
        </label>
    </div>


    <div class="footer_wrap">

    </div>

    <script>
        //隐藏提示
        $(document).on("click", ".exam_top .close", function() {
            $(this).closest(".tips").hide();
        });
        document.onkeydown = function(e) {
            e = window.event || e;
            var k = e.keyCode;
            //屏蔽ctrl+R，F5键，ctrl+F5键  F3键！验证
            if ((e.ctrlKey == true && k == 82) || (k == 116) ||
                (e.ctrlKey == true && k == 116) || k == 114) {
                e.keyCode = 0;
                alert("当前页面不能刷新！");
                e.returnValue = false;
                e.cancelBubble = true;
                return false;

            }
        }
        fun_islogin();
        //勾选checked
        $(document).on("change", ".answer input", function() {
            var $tmp_exam_answer = $(this).closest(".answer");
            $tmp_exam_answer.find(".checked").removeClass("checked");
            $tmp_exam_answer.find(":checked").closest(".form_check").addClass("checked");
        });

        //获取场次id
        getQueryString(name);

        var get_timesId = getQueryString("timesId").trim(); //场次
        var get_pointId = getQueryString("pointId"); //pointId
        if (get_pointId) {
            get_pointId = get_pointId.trim()
        };
        var get_userId = localStorage.getItem("userId"); //userid
        var get_roleCode = localStorage.getItem("roleCode"); //roleCode
        var tmp_papertype; //试卷角色类型

        //载入试卷
        var tmp_parms = {
            pageSize: 100,
            pageNum: 1,
            userId: get_userId, //用户id
            timesId: get_timesId, //场次 13
            roleCode: get_roleCode
        };

        // console.log(GET_EXAM_LIST,123)
        $.ajax({
            type: "POST",
            url: GET_EXAM_LIST,
            //url: "192.168.3.133:9600/TestPaperQuestionRecord/add",
            dataType: "json",
            data: tmp_parms,
            async: false,
            timeout: 20000,
            beforeSend: function(XMLHttpRequest) {
                $.fn.winktips("正在载入考卷，请稍后...");
            },
            success: function(data, textStatus) {
                if (typeof data != "object") {
                    data = $.parseJSON(data);
                }
                if (data.status == 1) {
                    var fetch_data = data.data;
                    //考卷标题
                    $(".exam_top .title").text(fetch_data.examinationTimes.timesName);

                    //paperId
                    //tmp_paperId = fetch_data.testPaper.id;
                    //试卷角色类型
                    tmp_papertype = fetch_data.examinationTimes.type;

                    //考题
                    var $tmp_html = $("<div/>");
                    for (var i = 0; i < fetch_data.list.length; i++) {
                        $tmp_item = $("#tmp_item_exam .item").clone();
                        //console.log(fetch_data.list.length)

                        //单选题
                        if (fetch_data.list[i].type == 0) {
                            $tmp_item.find(".questiontype").text("第" + (i + 1) + "题 单选题");
                            $tmp_item.find(".questiontype").attr("data-type", "0");
                        }
                        //多选题
                        if (fetch_data.list[i].type == 1) {
                            $tmp_item.find(".questiontype").text("第" + (i + 1) + "题 多选题");
                            $tmp_item.find(".questiontype").attr("data-type", "1");
                        }
                        //判断题
                        if (fetch_data.list[i].type == 2) {
                            $tmp_item.find(".questiontype").text("第" + (i + 1) + "题 判断题");
                            $tmp_item.find(".questiontype").attr("data-type", "2");
                        }

                        //考题名称
                        $tmp_item.find(".question").text(fetch_data.list[i].topicName);
                        //考题图片
                        if (!fetch_data.list[i].imgUrl || fetch_data.list[i].imgUrl == "") {
                            //$(".questionimg").hide();
                        } else {
                            //$tmp_item.find(".questionimg img").attr("src", fetch_data.list[i].imgUrl);
                            $tmp_item.find(".questionimg").html("<img src='" + fetch_data.list[i].imgUrl + "'/>");
                        }

                        //题目id
                        $tmp_item.attr("data-id", fetch_data.list[i].id);

                        //题目分数
                        $tmp_item.attr("data-score", fetch_data.list[i].score);


                        //判断题目类型
                        var type_input;

                        if (fetch_data.list[i].type == 1) {
                            type_input = 'checkbox';
                        } else {
                            type_input = 'radio';
                        }


                        //选项
                        var $tmp_htmllabel = $("<div/>");
                        //var tmp_re = fetch_data.list[i].chooses.reverse(); //倒序
                        $.each(fetch_data.list[i].chooses, function(ch_i, ch_n) {
                            var z = String.fromCharCode((65 + ch_i)); //顺序字母
                            $tmp_label = $("#tmp_item_check .form_check").clone();
                            $tmp_label.find(".input_change").attr("type", type_input);
                            $tmp_label.find(".input_change").attr("name", 'answer_' + ch_n.tId);
                            $tmp_label.find(".input_change").val(ch_n.id);

                            //$tmp_label.find(".change_head").text(ch_n.chooseHead);
                            $tmp_label.find(".change_head").text(z);
                            $tmp_label.find(".change_name").text(ch_n.chooseName);

                            $tmp_label.find(".change_img img").attr("src", ch_n.chooseName);

                            $tmp_label.find(".input_change").data("an", ch_n.isAnswer);

                            $tmp_htmllabel.append($tmp_label);
                        });

                        $tmp_htmllabel.find(".form_check").appendTo($tmp_item.find(".answer"));

                        //图片题
                        if (fetch_data.list[i].isImage == 1) {


                            $tmp_item.addClass("isimg");
                            $tmp_item.attr("data-img", 1);
                            //$tmp_item.find(".change_name").hide();
                        } else {
                            $tmp_item.removeClass("isimg");
                            $tmp_item.attr("data-img", 0);
                            //$tmp_item.find(".change_img").hide();
                        }



                        $tmp_html.append($tmp_item);
                    }

                    $tmp_html.find(".item").appendTo("#exam_box .list");

                    //考试时长
                    var exam_time = fetch_data.examinationTimes.duringTime;

                    $(".exam_totaltime .text").text(exam_time)


                } else {
                    $.fn.winktips(data.msg);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $.fn.winktips("连接超时，请检查您的网络");
            }
        });

        //获取倒计时
        fun_examtime();

        function fun_examtime() {
            var tmp_parms = {
                userId: get_userId, //用户id
                timesId: get_timesId, //场次 13
                roleCode: get_roleCode
            };
            $.ajax({
                type: "POST",
                url: GET_EXAM_TIME,
                dataType: "json",
                data: tmp_parms,
                async: false,
                timeout: 20000,
                beforeSend: function(XMLHttpRequest) {

                },
                success: function(data, textStatus) {
                    if (data.status == 1) {
                        var cut_time = data.data;
                        //倒计时
                        var nowtime = (new Date()).getTime();
                        var tmp_time = parseInt(cut_time);
                        //var tmp_time = parseInt(10);
                        timer(tmp_time);
                    }
                }
            });

        };


        //倒计时
        function timer(tmp_time) {
            var tmp_tipetime = 300; //五分钟提示
            time = setInterval(function() {
                var day = 0,
                    hour = 0,
                    minute = 0,
                    second = 0; //时间默认值

                if (tmp_time >= 0) {
                    day = Math.floor(tmp_time / (60 * 60 * 24));
                    hour = Math.floor(tmp_time / (60 * 60)) - (day * 24);
                    minute = Math.floor(tmp_time / 60) - (day * 24 * 60) - (hour * 60);
                    second = Math.floor(tmp_time) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
                    if (minute <= 9) minute = '0' + minute;
                    if (second <= 9) second = '0' + second;

                    //$('#day_show').html(day + "天");
                    $('#hour_show').html(hour + ':');
                    $('#minute_show').html(minute + ':');
                    $('#second_show').html(second);

                    tmp_time--;

                    if (tmp_time == tmp_tipetime) {
                        //$.fn.winktips("距离考试结束还有五分钟");
                        $.fn.winktips({
                            con: "距离考试结束还有五分钟",
                            delay: 5000
                        });

                    }
                } else {
                    clearInterval(time);
                    //$.fn.poptips("时间到，考试结束");
                    //自动交卷
                    fun_autosubmit();
                }

            }, 1000);
        };




        //自动提交
        function fun_autosubmit() {
            var timestamp = (new Date()).getTime();
            getQueryString();
            var get_timesId = getQueryString("timesId");
            var tmp_parms = {
                //"paperId": tmp_paperId, //考卷id
                "userId": get_userId, //用户id
                "timesId": get_timesId, //场次
                "createDate": timestamp, //作答时间
                "pointId": get_pointId, //考点id
                "type": tmp_papertype, //类型
                "paperName": $(".exam_top .title").text(), //考卷名称
                "topics": "" //考题数组
            };

            var tmp_subject = []; //题目

            $("#exam_box .item").each(function() {

                var tmp_option = []; //选项
                var tmp_checked = []; //选择
                $(this).find(".form_check").each(function() {
                    //console.log($(this).find(".input_change").data("an"))
                    tmp_option.push({
                        "id": $(this).find("input").val(),
                        "chooseName": $(this).find(".change_name").text(),
                        "chooseHead": $(this).find(".change_head").text(),
                        "isAnswer": $(this).find(".input_change").data("an")
                    });
                });
                $(this).find(":checked").each(function() {
                    tmp_checked.push({
                        "id_head": $(this).closest(".checked").find(".change_head").text(),
                        "id": $(this).val()
                    });
                });

                tmp_subject.push({
                    "id": $(this).data("id"),
                    "topicName": $(this).find(".question").text(),
                    "imgUrl": $(this).find(".questionimg img").attr("src"),
                    "chooses": tmp_option,
                    "userChoose": tmp_checked,
                    "type": $(this).find(".questiontype").data("type"),
                    "isImg": $(this).data("img")
                })

            })

            tmp_parms.topics = JSON.stringify(tmp_subject);
            //console.log(tmp_parms.topics)

            $.ajax({
                type: "POST",
                url: POST_EXAM_ADD,
                dataType: "json",
                data: tmp_parms,
                timeout: 20000,
                beforeSend: function(XMLHttpRequest) {
                    //$this_btn.addClass("disabled").text("提交中……");
                },
                success: function(data, textStatus) {
                    if (data.status == 1) {

                        $.fn.poptips({
                            title: "时间到，考试结束", //默认为空
                            con: "系统已自动交卷，前往查看分数",
                            conCenter: false, //文本内容内容是否居中，默认居中
                            //btnOK: false, //是否显示确认按钮 默认显示
                            //btnCancel: true, //是否显示取消按钮 默认不显示
                            btnOKText: "去查看", //确认按钮的文案
                            btnCancelText: "回中心", //取消按钮的文案
                            btnOKClick: function() { //确认按钮点击事件（没有按钮时遵从此事件）

                                //window.location.href = "./exam_resoult.html?paperId=" + tmp_paperId + '&timesId=' + get_timesId; //查看分数
                                window.location.href = "./exam_resoult.html?timesId= " + get_timesId; //查看分数
                            },
                            btnCancelClick: function() { //取消按钮点击事件
                                //window.history.go(-1); //返回控制中心
                            }
                        });


                    } else if (data.status == 0) {
                        $.fn.winktips("提交失败");
                    } else {
                        $.fn.winktips(data.msg);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $.fn.winktips("连接超时，请检查您的网络");
                },
                complete: function() {
                    //$this_btn.removeClass("disabled").text("立即提交");
                }
            });


        };

        //点击提交
        fun_submit();

        function fun_submit() {
            $("#btn_submit").on('click', function() {
                var $this_btn = $(this);
                var timestamp = (new Date()).getTime();

                var tmp_parms = {
                    //"userChoose": tmp_answer, //选择答案
                    //"paperId": tmp_paperId, //考卷id
                    "userId": get_userId, //用户id
                    "timesId": get_timesId, //场次 13 get_timesId
                    "createDate": timestamp, //作答时间
                    "pointId": get_pointId, //考点id
                    "type": tmp_papertype, //类型
                    "paperName": $(".exam_top .title").text(), //考卷名称
                    "topics": "" //考题数组
                };
                //是否答题完整
                var tmp_sorry = 0;
                $("#exam_box .answer").each(function() {
                    if (!$(this).find(":checked").length) {
                        $.fn.winktips("有题目尚未解答");
                        $("html, body").animate({
                            scrollTop: $(this).closest(".item").offset().top - 100
                        }, "slow");
                        tmp_sorry = 1;
                        return false;
                    }
                });

                if (tmp_sorry) {
                    return false;
                };

                var tmp_subject = []; //题目

                $("#exam_box .item").each(function() {

                    var tmp_option = []; //选项
                    var tmp_checked = []; //选择
                    $(this).find(".form_check").each(function() {
                        tmp_option.push({
                            "id": $(this).find("input").val(),
                            "chooseName": $(this).find(".change_name").text(),
                            "chooseHead": $(this).find(".change_head").text(),
                            "isAnswer": $(this).find("input").data("an")
                        });
                    });
                    $(this).find(":checked").each(function() {
                        tmp_checked.push({
                            "id_head": $(this).closest(".checked").find(".change_head").text(),
                            "id": $(this).val()
                        });
                    });

                    tmp_subject.push({
                        "id": $(this).data("id"),
                        "score": $(this).data("score"),
                        "topicName": $(this).find(".question").text(),
                        "imgUrl": $(this).find(".questionimg img").attr("src"),
                        "chooses": tmp_option,
                        "userChoose": tmp_checked,
                        "type": $(this).find(".questiontype").data("type"),
                        "isImg": $(this).data("img")
                    })

                })

                tmp_parms.topics = JSON.stringify(tmp_subject);

                //console.log(tmp_subject)

                $.fn.poptips({
                    //title: "", //默认为空
                    con: "是否现在交卷",
                    conCenter: false, //文本内容内容是否居中，默认居中
                    //btnOK: false, //是否显示确认按钮 默认显示
                    btnCancel: true, //是否显示取消按钮 默认不显示
                    btnOKText: "确定", //确认按钮的文案
                    btnCancelText: "取消", //取消按钮的文案
                    btnOKClick: function() { //确认按钮点击事件（没有按钮时遵从此事件）

                        $.ajax({
                            type: "POST",
                            url: POST_EXAM_ADD,
                            //url: "HTTP://192.168.3.133:9600/TestPaperQuestionRecord/add",
                            dataType: "json",
                            data: tmp_parms,
                            timeout: 20000,
                            //async: false,
                            beforeSend: function(XMLHttpRequest) {
                                $this_btn.addClass("disabled").text("提交中……");
                            },
                            success: function(data, textStatus) {
                                if (data.status == 1) {

                                    $.fn.poptips({
                                        title: "试卷已提交", //默认为空
                                        con: "前往查看分数",
                                        conCenter: false, //文本内容内容是否居中，默认居中
                                        //btnOK: false, //是否显示确认按钮 默认显示
                                        //btnCancel: true, //是否显示取消按钮 默认不显示
                                        btnOKText: "去查看", //确认按钮的文案
                                        btnCancelText: "回中心", //取消按钮的文案
                                        btnOKClick: function() { //确认按钮点击事件（没有按钮时遵从此事件）

                                            //window.location.href = "./exam_resoult.html?paperId=" + tmp_paperId + '&timesId=' + get_timesId; //查看分数
                                            window.location.href = "./exam_resoult.html?timesId=" + get_timesId; //查看分数
                                        },
                                        btnCancelClick: function() { //取消按钮点击事件
                                            //window.history.go(-1);
                                        }
                                    });


                                } else if (data.status == 0) {
                                    $.fn.winktips("提交失败");
                                } else {
                                    $.fn.winktips(data.msg);
                                }
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                $.fn.winktips("连接超时，请检查您的网络");
                            },
                            complete: function() {
                                $this_btn.removeClass("disabled").text("交卷");
                            }
                        });
                    },
                    btnCancelClick: function() { //取消按钮点击事件

                    }
                });


            })
        };

        $(document).on("click", ".btn_out", function() {
            $.fn.poptips({
                title: "注意！", //默认为空
                con: "你确定要退出考试吗",
                conCenter: false, //文本内容内容是否居中，默认居中
                //btnOK: false, //是否显示确认按钮 默认显示
                btnCancel: true, //是否显示取消按钮 默认不显示
                btnOKText: "退出", //确认按钮的文案
                btnCancelText: "取消", //取消按钮的文案
                btnOKClick: function() { //确认按钮点击事件（没有按钮时遵从此事件）
                    var userAgent = navigator.userAgent;
                    if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
                        window.location.href = "about:blank";
                        window.close();
                    } else {
                        window.opener = null;
                        window.open("", "_self");
                        window.close();
                    }
                },
                btnCancelClick: function() { //取消按钮点击事件
                    //window.history.go(-1); //返回控制中心
                }
            });
        })
    </script>
</body>

</html>
